#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 2e5 + 10;

ll read(){
    ll x = 0, t = 1;
    char c = getchar();
    while(c < '0' || c > '9'){
        if(c == '-') t = -t;
        c = getchar();
    }
    while(c >= '0' && c <= '9'){
        x = (x << 1) + (x << 3) + (c ^ 48);
        c = getchar();
    }

    return x * t;
}

void print(ll x){
    if(x < 0){
        putchar('-');
        print(-x);
        return;
    }
    if(x > 9){
        print(x / 10);
    }
    putchar((x % 10) ^ 48);
}

ll n, m;
ll T;
ll a[N];

ll dp[2][2][200010];

int main(){
    freopen("color.in", "r", stdin);
    freopen("color.out", "w", stdout);

    T = read();
    while(T--){
        n = read();
        
        for(int i = 1; i <= n; i++){
            a[i] = read();
        }
        if(n > 20000){
            putchar('0');
            putchar('\n');
            continue;
        }
        for(int i = 1; i <= n; i++){
            for(int j = 0; j <= n; j++)
            {
                dp[i % 2][0][j] = dp[i % 2][1][j] = 0;
            }
            for(int j = 0; j <= i-2; j++){
                dp[i % 2][0][i - 1] = max(dp[i % 2][0][i - 1],dp[(i - 1) % 2][1][j] + (a[i] == a[j] ? a[i] : 0));//choose
                dp[i % 2][0][j] = max(dp[i % 2][0][j], dp[(i - 1) % 2][0][j] + (a[i] == a[i - 1] ? a[i] : 0));//not choose
                dp[i % 2][1][i - 1] = max(dp[i % 2][1][i - 1], dp[(i - 1) % 2][0][j] + (a[i] == a[j] ? a[i] : 0));
                dp[i % 2][1][j] = max(dp[i % 2][1][j], dp[(i - 1) % 2][1][j] + (a[i] == a[i - 1] ? a[i] : 0));
            }
        }
        ll ans = 0;
        for(int i = 0; i <= n; i++){
            ans = max(ans, dp[n % 2][0][i]);
        }
        print(ans);
        putchar('\n');

        for(int i = 0; i <= 1; i++){
            for(int j = 0; j <= n; j++){
                dp[i][0][j] = dp[i][1][j] = 0;
            }
        }
    }

    return 0;
}